<?php

class Languages {

    function getAllLabelsByLang($labels, $lang) {
        $result = NULL;

        if ($labels !== NULL) {
            $labels = $labels["labels"];
            $label = $labels["label"];

            $label_obj = array();
            foreach ($label as $lb) {
                $key = $lb["key"];
                $value = $lb[$lang];
                $label_obj[$key] = $value;
            }
            $label_key = array();
            $label_key["label"] = $label_obj;

            $result = $label_key;
        }

        return $result;
    }

    function getAllLabels() {
        $result = NULL;

        $langDB = new PDO('sqlite:lang/languages.sqlite');
        $query = "SELECT * FROM labels";
        $excute = $langDB->query($query);
        if ($excute) {
            $label_arr = array();
            while ($row = $excute->fetch()) {
                $label_obj = array();
                $label_obj['key'] = $row['key'];
                $label_obj['vi'] = $row['vi'];
                $label_obj['en'] = $row['en'];
                array_push($label_arr, $label_obj);
            }

            $label_key = array();
            $labels_key = array();
            $label_key['label'] = $label_arr;
            $labels_key['labels'] = $label_key;

            $result = $labels_key;
        }

        return $result;
    }

}
